package com.poly.flowable.controller;

import com.poly.common.core.domain.R;
import com.poly.common.core.utils.poi.ExcelUtil;
import com.poly.common.core.web.controller.BaseController;
import com.poly.common.core.web.page.TableDataInfo;
import com.poly.common.security.annotation.RequiresPermissions;
import com.poly.flowable.domain.SysExpression;
import com.poly.flowable.service.ISysExpressionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 流程达式Controller
 * 
 * @author Poly
 * @date 2022-12-12
 */
@RestController
@RequestMapping("/expression")
public class SysExpressionController extends BaseController
{
    @Autowired
    private ISysExpressionService sysExpressionService;

    /**
     * 查询流程达式列表
     */
    @RequiresPermissions("system:expression:list")
    @GetMapping("/list")
    public TableDataInfo list(SysExpression sysExpression)
    {
        startPage();
        List<SysExpression> list = sysExpressionService.selectSysExpressionList(sysExpression);
        return getDataTable(list);
    }

    /**
     * 导出流程达式列表
     */
    @RequiresPermissions("system:expression:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysExpression sysExpression)
    {
        List<SysExpression> list = sysExpressionService.selectSysExpressionList(sysExpression);
        ExcelUtil<SysExpression> util = new ExcelUtil<SysExpression>(SysExpression.class);
        util.exportExcel(response, list, "流程达式数据");
    }

    /**
     * 获取流程达式详细信息
     */
    @RequiresPermissions("system:expression:query")
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id)
    {
        return R.ok(sysExpressionService.selectSysExpressionById(id));
    }

    /**
     * 新增流程达式
     */
    @RequiresPermissions("system:expression:add")
    @PostMapping
    public R add(@RequestBody SysExpression sysExpression)
    {
        return toResult(sysExpressionService.insertSysExpression(sysExpression));
    }

    /**
     * 修改流程达式
     */
    @RequiresPermissions("system:expression:edit")
    @PutMapping
    public R edit(@RequestBody SysExpression sysExpression)
    {
        return toResult(sysExpressionService.updateSysExpression(sysExpression));
    }

    /**
     * 删除流程达式
     */
    @RequiresPermissions("system:expression:remove")
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids)
    {
        return toResult(sysExpressionService.deleteSysExpressionByIds(ids));
    }
}
